/* 
  UbloxGPS - a small library to manage a ublox GPS
  
  This library creates a sub-class of Mikal Hart's TinyGPS
  to specifically work with Serial Port u-blox GPS modules 
  implementing the u-blox 6 protocol (e.g. the ADH Technology
  GP-635T)
  
  www.u-blox.com
  www.adh-tech.com.tw

*/

#ifndef UbloxGPS_h
#define UbloxGPS_h

#include "Arduino.h"
#include <TinyGPS.h>

class UbloxGPS : public TinyGPS
{
  public:
  
    UbloxGPS(void);    
    Stream* thePort;

    byte ggaID, gllID, gsaID, gsvID, rmcID, vtgID, nmeaClass;

    
    long lat;                // lat, lon in deg x 10^6 (mod) or 10^5 (Hart)
    long lon;                // altitude in centimeters (m x 100)
    long alt;

    unsigned long gps_age(void); // returns millis since last gps fix
    unsigned long gps_time;      // time of gps fix in mills

    /*
    int g_course;
    int g_speed;             // course x 10 degrees, speed in cm/s (m/s x 100)
    int cos_course;
    int sin_course;          // cos, sin of course, Fix_16_15
    int v_north;
    int v_east;              // North and East component of velocity, cm/s
    */
    
    int err;                      // An error value, returned by the set methods
                                  // 1 = NAK, -1 = Timeout
    int timeOut;                  // set Method timeout, default = 2s
    int validTime;                // GPS valid age, default = 5s
    int validChar;
    unsigned long charTime;
    unsigned long avlTime;

    byte status;
    
    void begin(Stream &port);
    boolean gps_valid(void);

    boolean process(void);    
    boolean setMode(byte mode);    
    boolean setMsgRate(byte msgClass, byte msgID, byte rate[]);    
    /*
    static int fp_sin(int deg10);    
    static int fp_cos(int deg10);
    */

  private:
    int startAck, ack1, ack2, ack3;
    byte ckA, ckB;
    void send_header(void);
    void send_byte(byte b);
    void send_byte(byte b[], int length);
    boolean get_ack(void);    
    /*
    static int itrig(int deg10);
    */
};

#endif